package cn.myframe;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * @Author: ynz
 * @Date: 2019/9/4/004 10:39
 * @Version 1.0
 */
public class Test {

    public static void main(String[] args) {
        int count = 10000;
        Jedis jedis = new Jedis("127.0.0.1", 6379);

        System.out.println("清空数据" + jedis.flushDB());
        System.out.println("判断某个键是否存在: " + jedis.exists("username"));
        System.out.println("新增'<username, mxz>的键值对'" + jedis.set("username", "mxz"));
        System.out.println("新增'<password, mxz>的键值对'" + jedis.set("password", "mxz"));

        System.out.println("系统中所有的键值对如下: ");
        Set<String> keys = jedis.keys("*");
        System.out.println(keys);

        System.out.println(jedis.hset("user", "1", "{name:张三，username：zhangsan，workerNo:1255}"));
        System.out.println(jedis.hset("user", "2", "{name:李四，username：zhangsan，workerNo:1255}"));
        System.out.println(jedis.hset("user", "3", "{name:王五，username：zhangsan，workerNo:1255}"));
        System.out.println(jedis.hset("user", "4", "{name:黄老师，username：zhangsan，workerNo:1255}"));

        keys = jedis.keys("*");
        System.out.println(keys);

        System.out.println("删除键password: " + jedis.del("password"));
        System.out.println("判断键password是否存在: " + jedis.exists("password"));
        System.out.println("查看键username所存储值的类型: " + jedis.type("username"));
        System.out.println("随机返回key空间的一个: " + jedis.randomKey());
        System.out.println("重命名key: " + jedis.rename("username", "name"));
        System.out.println("按索引查询: " + jedis.select(0));
        System.out.println("删除当前选择数据库的所有的key: " + jedis.flushDB());
        System.out.println("返回当前数据库中key的数目: " + jedis.dbSize());
        System.out.println("删除所有数据库中的所有的key: " + jedis.flushAll());
        jedis.close();
    }
}
